package com.k3cloud.user.user;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.hustcad.plm.pdm.partbom.vo.PartDetailsVO;
import com.k3cloud.base.dto.entity.ExecutionTypeDO;
import com.k3cloud.base.service.AddAttributesDataToInService;
import com.k3cloud.base.type.AttributesInterfaceType;
import com.k3cloud.user.service.UserK3cloudService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@AttributesInterfaceType(typeValue = "MaterialsHandling",classificationValue="k3cloudProject")
public class TestMaterialGroupingServiceImpl implements AddAttributesDataToInService {

    /**
     * 物料保存接口添加物料分组值
     * @param partDetailsJson
     * @param partDetails
     */
    @Override
    public void addAttributesToPartDetailsJson(ExecutionTypeDO executionTypeDO, JSONObject partDetailsJson, Object partDetails, Object parameter) {
        UserK3cloudService userK3cloudService = SpringUtil.getBean(UserK3cloudService.class);

        if(partDetails instanceof PartDetailsVO){
            PartDetailsVO partDetailsVO= (PartDetailsVO) partDetails;
            List<Map<String, Object>> baseCodeList = userK3cloudService.getBaseCode(partDetailsVO.getClassId());
            if (baseCodeList != null && baseCodeList.size() > 0) {
                partDetailsJson.put("baseClassificationCode", baseCodeList.get(0).get("objectnumber"));
            }
        }

    }
}
